﻿Imports System.Web.SessionState
Imports System.Web
Imports System.Web.Routing

Public Class Global_asax
    Inherits System.Web.HttpApplication

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is startet
        RouteTable.Routes.Add(New Route("{resource}.axd/{*pathInfo}", New StopRoutingHandler()))
        RouteTable.Routes.Add(New Route("Scripts/{*pathInfo}", New StopRoutingHandler()))
        RouteTable.Routes.Add(New Route("Style/{*pathInfo}", New StopRoutingHandler()))
        RouteTable.Routes.Add(New Route("Images/{*pathInfo}", New StopRoutingHandler()))

        RouteTable.Routes.Add("DefaultPage", New Route("", New RouteHandler("~/TopPage.aspx")))
        RouteTable.Routes.Add("RepairService", New Route("gioi-thieu", New RouteHandler("~/RepairServicePage.aspx")))
        RouteTable.Routes.Add("MaintenanceService", New Route("huong-dan-mua-hang", New RouteHandler("~/MaintenanceServicePage.aspx")))
        RouteTable.Routes.Add("BuyService", New Route("lien-he", New RouteHandler("~/BuyServicePage.aspx")))
        RouteTable.Routes.Add("SearchPage", New Route("Search/keyword={keyword}", New RouteHandler("~/Pages/SearchPage.aspx")))
        Dim routeSearchPage As New Route("Search/keyword={keyword}/page-{page}", New RouteHandler("~/Pages/SearchPage.aspx"))
        routeSearchPage.Constraints = New RouteValueDictionary(New With {.page = "\d{1,2}"})
        RouteTable.Routes.Add("SearchPaging", routeSearchPage)
        RouteTable.Routes.Add("Error", New Route("error", New RouteHandler("~/Pages/Error.aspx")))
        RouteTable.Routes.Add("Management", New Route("management", New RouteHandler("~/Admin/HomePageEdit.aspx")))
        RouteTable.Routes.Add("login", New Route("login", New RouteHandler("~/Logon/Logon.aspx")))
        RouteTable.Routes.Add("NewsList", New Route("kinh-nghiem-su-dung-do-go", New RouteHandler("~/Pages/NewsList.aspx")))
        Dim routeNewsListPage As New Route("kinh-nghiem-su-dung-do-go/page-{page}", New RouteHandler("~/Pages/NewsList.aspx"))
        routeNewsListPage.Constraints = New RouteValueDictionary(New With {.page = "\d{1,2}"})
        RouteTable.Routes.Add("NewsListPaging", routeNewsListPage)
        RouteTable.Routes.Add("NewsDetail", New Route("kinh-nghiem-su-dung-do-go/{newsdetail}", New RouteHandler("~/Pages/NewsDetail.aspx")))
        RouteTable.Routes.Add("NewsSearch", New Route("kinh-nghiem-su-dung-do-go/search/{tag}", New RouteHandler("~/Pages/NewsList.aspx")))
        Dim routeNewsSearchPage As New Route("kinh-nghiem-su-dung-do-go/search/{tag}/page-{page}", New RouteHandler("~/Pages/NewsList.aspx"))
        routeNewsSearchPage.Constraints = New RouteValueDictionary(New With {.page = "\d{1,2}"})
        RouteTable.Routes.Add("NewsSearchPaging", routeNewsSearchPage)
        RouteTable.Routes.Add("ProductList", New Route("{category}/{manufactory}", New RouteHandler("~/Pages/ProductList.aspx")))
        Dim routeProductListPage As New Route("{category}/{manufactory}/page-{page}", New RouteHandler("~/Pages/ProductList.aspx"))
        routeProductListPage.Constraints = New RouteValueDictionary(New With {.page = "\d{1,2}"})
        RouteTable.Routes.Add("ProductListPaging", routeProductListPage)
        RouteTable.Routes.Add("ProductDetail", New Route("{category}/{manufactory}/{product}", New RouteHandler("~/Pages/ProductDetail.aspx")))
        RouteTable.Routes.Add("CatchAll", New Route("{*category}", New RouteHandler("~/Pages/Error.aspx")))
        
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session is started
    End Sub

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires upon attempting to authenticate the use
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session ends
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application ends
    End Sub

End Class